﻿Imports System.Linq
Imports TNCDAL

Public Class FileMBLController
    Private objRepository As New FileMBLRepository

    Public Function SelectRecordById(ByVal id As Integer) As tblFileMBL
        Return objRepository.SelectRecordById(id)
    End Function

    Public Function SelectRecordById(ByVal id_File As Integer, ByVal id_MBL As Integer) As tblFileMBL
        Return objRepository.SelectRecordById(id_File)
    End Function

    Public Sub Insert(ByVal obj As tblFileMBL)
        objRepository.Insert(obj)
    End Sub

    Public Sub Update(ByVal obj As tblFileMBL)
        objRepository.Update(obj)
    End Sub

    Public Sub Delete(ByVal obj As tblFileMBL)
        objRepository.Delete(obj)
    End Sub

    Public Function GetCustomFileMBLList(ByVal id_file As Integer) As IQueryable
        Dim query As IQueryable = From p In objRepository.GetFileMBLList(id_file)
                                    Select p.ID_FileMBL, p.tblFile, p.tblMBL.MBLNo, p.tblMBL.tblVoyage.tblLine.LineName,
                                    p.tblMBL.tblVoyage.tblVessel.VesselName, p.tblMBL.tblVoyage.VoyageNo, POL = p.tblMBL.tblVoyage.tblPort.Port, POD = p.tblMBL.tblVoyage.tblPort1.Port,
                                    p.tblMBL.tblVoyage.ETA, p.tblMBL.tblVoyage.ETD

        Return query
    End Function

    ''' <summary>
    ''' Lấy MBL mà có ngày POL > ngày hiện tại
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function GetCustomFileMBLList() As IQueryable
        Dim query As IQueryable = From p In objRepository.SelectAllRecords()
                                    Select p.ID_FileMBL, p.tblFile, p.tblMBL.MBLNo, p.tblMBL.tblVoyage.tblLine.LineName,
                                    p.tblMBL.tblVoyage.tblVessel.VesselName, p.tblMBL.tblVoyage.VoyageNo, POL = p.tblMBL.tblVoyage.tblPort.Port, POD = p.tblMBL.tblVoyage.tblPort1.Port,
                                    p.tblMBL.tblVoyage.ETA, p.tblMBL.tblVoyage.ETD
        Return query
    End Function

    Public Function GetMBLList(ByVal id_file As Integer) As IQueryable(Of tblMBL)
        Return objRepository.GetMBLList(id_file)
    End Function

    Public Function GetMBLByFile(ByVal id_file As Integer) As tblFileMBL
        Return objRepository.GetMBLByFile(id_file)
    End Function
End Class
